﻿namespace Reap.AzureResource.Data.Infrastructure
{
	using System;

	using Reap.Common.Runtime.Dependency;

	[Dependency(typeof (IDisposable), ComponentLifeStyle.InRequestScope, Key = "IDisposable")]
	public class Disposable : IDisposable
	{
		#region Fields

		private bool isDisposed;

		#endregion

		#region Constructors and Destructors

		~Disposable()
		{
			this.Dispose(false);
		}

		#endregion

		#region Public Methods and Operators

		public void Dispose()
		{
			this.Dispose(true);
			GC.SuppressFinalize(this);
		}

		#endregion

		#region Methods

		protected virtual void DisposeCore()
		{
		}

		private void Dispose(bool isDisposing)
		{
			if (!this.isDisposed && isDisposing)
			{
				this.DisposeCore();
			}
			this.isDisposed = true;
		}

		#endregion
	}
}